package com.lagou.edu.course.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lagou.edu.course.api.CourseRemoteService;
import com.lagou.edu.course.api.dto.*;
import com.lagou.edu.course.api.enums.CourseStatus;
import com.lagou.edu.course.api.param.CourseQueryParam;
import com.lagou.edu.course.entity.po.Course;
import com.lagou.edu.course.remote.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;


    /**
     * 获取选课列表
     * @param userId
     * @return
     */
    @GetMapping("/getAllCourses")
    public List<CourseDTO> getAllCourses(@RequestParam(required = false,name = "userId") Integer userId) {
        return  courseService.getAllCourses(userId);
    }



    @GetMapping("/getCourseById")
    public CourseDTO getCourseById(@RequestParam("courseId") Integer courseId,@RequestParam("userId") Integer userId){
        return courseService.getCourseById(courseId,userId);
    }

    @PostMapping("/saveOrUpdateCourse")
    public boolean saveOrUpdateCourse(@RequestBody CourseDTO courseDTO) {
        return courseService.saveOrUpdateCourse(courseDTO);
    }

    @PostMapping("/getQueryCourses")
    public PageResultDTO<CourseDTO> getQueryCourses(@RequestBody CourseQueryParam courseQueryParam) {
        return courseService.getQueryCourses(courseQueryParam);
    }

    /**
     * 获取已购课程信息
     * @param userId
     * @return
     */
    @GetMapping("/getPurchasedCourse")
    List<CourseDTO> getPurchasedCourse(@RequestParam("userId") Integer userId){
        return  courseService.getPurchasedCourse(userId);
    }



}
